#include <SDL.h>
#include "Controller.h"

Controller::Controller()
{
	m_playerMap.jump =false;
	m_playerMap.forward = false;
	m_playerMap.backward = false;
	m_playerMap.left = false;
	m_playerMap.right = false;
	m_playerMap.reset = false;

	m_cameraMap.forward = false;
	m_cameraMap.backward = false;
	m_cameraMap.left = false;
	m_cameraMap.right = false;
	m_cameraMap.up = false;
	m_cameraMap.down = false;

	m_cameraMap.rotateright = false;
	m_cameraMap.rotateup = false;
	m_cameraMap.rotateleft = false;
	m_cameraMap.rotatedown = false;
	m_cameraMap.showBounding = false;
	m_cameraMap.moveCamera = false;
	m_cameraMap.showNormals = false;
}

bool Controller::poll( const SDL_Event& event )
{
	switch ( event.key.keysym.sym ) {
		case SDLK_ESCAPE:
			return false; // signals quit
			break;

		// Player
		case SDLK_w:
			m_playerMap.forward = (event.type == SDL_KEYDOWN);
			break;
		case SDLK_a:
			m_playerMap.left = (event.type == SDL_KEYDOWN);
			break;		
		case SDLK_d:
			m_playerMap.right = (event.type == SDL_KEYDOWN);
			break;
		case SDLK_s:
			m_playerMap.backward = (event.type == SDL_KEYDOWN);
			break;
		case SDLK_SPACE:
			m_playerMap.jump = (event.type == SDL_KEYDOWN);
			break;

		// Camera
		case SDLK_UP:
			m_cameraMap.forward = (event.type == SDL_KEYDOWN);
			break;
		case SDLK_LEFT:
			m_cameraMap.left = (event.type == SDL_KEYDOWN);
			break;		
		case SDLK_RIGHT:
			m_cameraMap.right = (event.type == SDL_KEYDOWN);
			break;
		case SDLK_DOWN:
			m_cameraMap.backward = (event.type == SDL_KEYDOWN);
			break;
		case SDLK_PAGEUP:
			m_cameraMap.up = (event.type == SDL_KEYDOWN);
			break;
		case SDLK_PAGEDOWN:
			m_cameraMap.down = (event.type == SDL_KEYDOWN);
			break;

		case SDLK_i:
			m_cameraMap.rotateup = (event.type == SDL_KEYDOWN);
			break;
		case SDLK_j:
			m_cameraMap.rotateleft = (event.type == SDL_KEYDOWN);
			break;		
		case SDLK_k:
			m_cameraMap.rotatedown = (event.type == SDL_KEYDOWN);
			break;
		case SDLK_l:
			m_cameraMap.rotateright = (event.type == SDL_KEYDOWN);
			break;
		case SDLK_b: {
			if( (event.type == SDL_KEYDOWN) )
				m_cameraMap.showBounding = !m_cameraMap.showBounding;
			break;
			}
		case SDLK_c: {
			if( (event.type == SDL_KEYDOWN) )
				m_cameraMap.moveCamera = !m_cameraMap.moveCamera;
			break;
			}
		case SDLK_n: {
			if( (event.type == SDL_KEYDOWN) )
				m_cameraMap.showNormals = !m_cameraMap.showNormals;
			break;
		}
	}

	return true;
}
